home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / dvips / RCS / resident.c,v < prev    next >
Encoding:
Text File  |  1990-11-20  |  7.8 KB  |  363 lines

  1. head     1.3;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.3
  10. date     90.11.19.23.28.24;  author tve;  state Exp;
  11. branches ;
  12. next     1.2;
  13.  
  14. 1.2
  15. date     90.11.10.01.00.37;  author tve;  state Exp;
  16. branches ;
  17. next     1.1;
  18.  
  19. 1.1
  20. date     90.03.01.17.55.31;  author shirriff;  state Exp;
  21. branches ;
  22. next     ;
  23.  
  24.  
  25. desc
  26. @@
  27.  
  28.  
  29. 1.3
  30. log
  31. @fixed -P option
  32. ,
  33. @
  34. text
  35. @/*
  36.  *   This code reads in and handles the defaults for the program from the
  37.  *   file config.sw.  This entire file is a bit kludgy, sorry.
  38.  */
  39. #include "structures.h" /* The copyright notice in that file is included too! */
  40. /*
  41.  *   This is the structure definition for resident fonts.  We use
  42.  *   a small and simple hash table to handle these.  We don't need
  43.  *   a big hash table.
  44.  */
  45. struct resfont *reshash[RESHASHPRIME] ;
  46. /*
  47.  *   These are the external routines we use.
  48.  */
  49. extern void error() ;
  50. extern integer scalewidth() ;
  51. extern void tfmload() ;
  52. extern FILE *search() ;
  53. extern shalfword pkbyte() ;
  54. extern integer pkquad() ;
  55. extern integer pktrio() ;
  56. extern Boolean pkopen() ;
  57. extern char *strcpy() ;
  58. extern char *newstring() ;
  59. extern void add_header() ;
  60. /*
  61.  *   These are the external variables we use.
  62.  */
  63. #ifdef DEBUG
  64. extern integer debug_flag;
  65. #endif  /* DEBUG */
  66. extern long bytesleft ;
  67. extern quarterword *raster ;
  68. extern FILE *pkfile ;
  69. extern char *oname ;
  70. extern integer swmem ;
  71. extern char *tfmpath ;
  72. extern char *pkpath ;
  73. extern char *vfpath ;
  74. extern char *figpath ;
  75. extern char *nextstring ;
  76. extern char *maxstring ;
  77. extern Boolean disablecomments ;
  78. extern Boolean compressed ;
  79. extern int quiet ;
  80. extern int filter ;
  81. extern Boolean reverse ;
  82. extern Boolean usesPSfonts ;
  83. extern int actualdpi ;
  84. extern int maxdrift ;
  85. extern char *printer ;
  86. extern char *mfmode ;
  87. /*
  88.  *   We use malloc here.
  89.  */
  90. char *malloc() ;
  91. /*
  92.  *   Our hash routine.
  93.  */
  94. int
  95. hash(s)
  96.    char *s ;
  97. {
  98.    int h = 12 ;
  99.  
  100.    while (*s != 0)
  101.       h = (h + h + *s++) % RESHASHPRIME ;
  102.    return(h) ;
  103. }
  104.  
  105. /*
  106.  *   The routine that looks up a font name.
  107.  */
  108. struct resfont *
  109. lookup(name)
  110.    char *name ;
  111. {
  112.    struct resfont *p ;
  113.  
  114.    for (p=reshash[hash(name)]; p!=NULL; p=p->next)
  115.       if (strcmp(p->PSname, name)==0)
  116.          return(p) ;
  117.    return(NULL) ;
  118. }
  119. /*
  120.  *   This routine adds an entry.
  121.  */
  122. void
  123. add_entry(PSname, specinfo)
  124.    char *PSname, *specinfo ;
  125. {
  126.    struct resfont *p ;
  127.    int h ;
  128.  
  129.    p = (struct resfont *)malloc((unsigned int)sizeof(struct resfont)) ;
  130.    if (p==NULL)
  131.       error("! out of memory") ;
  132.    p->PSname = PSname ;
  133.    p->specialinstructions = specinfo ;
  134.    h = hash(PSname) ;
  135.    p->next = reshash[h] ;
  136.    reshash[h] = p ;
  137. }
  138. /*
  139.  *   Now our residentfont routine.
  140.  */
  141. Boolean
  142. residentfont(curfnt)
  143.         register fontdesctype *curfnt ;
  144. {
  145.    register shalfword i ;
  146.    struct resfont *p ;
  147.  
  148. /*
  149.  *   First we determine if we can find this font in the resident list.
  150.  */
  151.    if (*curfnt->area)
  152.       return 0 ; /* resident fonts never have a nonstandard font area */
  153.    if ((p=lookup(curfnt->name))==NULL)
  154.       return 0 ;
  155. /*
  156.  *   We clear out some pointers:
  157.  */
  158. #ifdef DEBUG
  159.    if (dd(D_FONTS))
  160.         (void)fprintf(stderr,"Font %s is resident.\n", curfnt->name) ;
  161. #endif  /* DEBUG */
  162.    curfnt->resfont = p ;
  163.    for (i=0; i<256; i++) {
  164.       curfnt->chardesc[i].TFMwidth = 0 ;
  165.       curfnt->chardesc[i].packptr = NULL ;
  166.       curfnt->chardesc[i].pixelwidth = 0 ;
  167.       curfnt->chardesc[i].flags = 0 ;
  168.    }
  169.    tfmload(curfnt) ;
  170.    usesPSfonts = 1 ;
  171.    return(1) ;
  172. }
  173. static char was_inline[100] ;
  174. void
  175. bad_config() {
  176.    error("Error in config file:") ;
  177.    (void)fprintf(stderr, was_inline) ;
  178.    exit(1) ;
  179. }
  180. /*
  181.  *   Now we have the getdefaults routine.
  182.  */
  183. void
  184. getdefaults(ext)
  185.    char *ext ;
  186. {
  187.    FILE *deffile ;
  188.    char PSname[100] ;
  189.    register char *p ;
  190.    char *specinfo, *fontname ;
  191.  
  192.    strcpy(PSname, "config.") ;
  193.    strcat(PSname, ext) ;
  194.  
  195.    if ((deffile=search(CONFIGPATH,PSname))!=NULL) {
  196.       while (fgets(was_inline, 100, deffile)!=NULL) {
  197.        switch (was_inline[0]) {
  198. case 'm' :
  199. #ifdef SHORTINT
  200.          if (sscanf(was_inline+1, "%ld", &swmem) != 1) bad_config() ;
  201. #else   /* ~SHORTINT */
  202.          if (sscanf(was_inline+1, "%d", &swmem) != 1) bad_config() ;
  203. #endif  /* ~SHORTINT */
  204.          break ;
  205. case 'M' :
  206.          if (sscanf(was_inline+1, "%s", PSname) != 1) bad_config() ;
  207.          mfmode = newstring(PSname) ;
  208.          break ;
  209. case 'o' : case 'O' :
  210.          p = was_inline + 1 ;
  211.          while (*p && *p <= ' ')
  212.             p++ ;
  213.      /* insert printer name */
  214.      if(strchr(p, '$')) {
  215.         char buf[200];
  216.         char *dollar = strchr(p, '$');
  217.         strncpy(buf, p, dollar-p); buf[dollar-p] = '\0';
  218.         if(printer != NULL)
  219.            strcat(buf, printer);
  220.         strcat(buf, dollar+1);
  221.         oname = newstring(buf);
  222.      } else {
  223.         oname = newstring(p);
  224.      }
  225.          break ;
  226. case 't' : case 'T' :
  227.          if (sscanf(was_inline+1, "%s", PSname) != 1) bad_config() ;
  228.          else tfmpath = newstring(PSname) ;
  229.          break ;
  230. case 'p' : case 'P' :
  231.          if (sscanf(was_inline+1, "%s", PSname) != 1) bad_config() ;
  232.          else pkpath = newstring(PSname) ;
  233.          break ;
  234. case 'v' : case 'V' :
  235.          if (sscanf(was_inline+1, "%s", PSname) != 1) bad_config() ;
  236.          else vfpath = newstring(PSname) ;
  237.          break ;
  238. case 's' : case 'S' :
  239.          if (sscanf(was_inline+1, "%s", PSname) != 1) bad_config() ;
  240.          else figpath = newstring(PSname) ;
  241.          break ;
  242. case ' ' : case '*' : case '#' : case ';' : case '=' : case 0 : case '\n' :
  243.          break ;
  244. case 'r' : case 'R' :
  245.          reverse = 1 ;
  246.          break ;
  247. case 'D' :
  248.          if (sscanf(was_inline+1, "%d", &actualdpi) != 1) bad_config() ;
  249.          if (actualdpi < 10 || actualdpi > 10000) bad_config() ;
  250.          break ;
  251. case 'e' :
  252.          if (sscanf(was_inline+1, "%d", &maxdrift) != 1) bad_config() ;
  253.          if (maxdrift < 0) bad_config() ;
  254.          break ;
  255. case 'q' : case 'Q' :
  256.          quiet = 1 ;
  257.          break ;
  258. case 'f' : case 'F' :
  259.          filter = 1 ;
  260.          break ;
  261. case 'h' : case 'H' :
  262.          if (sscanf(was_inline+1, "%s", PSname) != 1) bad_config() ;
  263.          else add_header(PSname) ;
  264.          break ;
  265. case 'N' :
  266.          disablecomments = 1 ;
  267.          break ;
  268. case 'Z' :
  269.          compressed = 1 ;
  270.          break ;
  271. default:
  272.          bad_config() ;
  273.       }
  274.      }
  275.      (void)fclose(deffile) ;
  276.      if (printer)
  277.         return ;
  278.    }
  279.    if ((deffile=search(CONFIGPATH,PSMAPFILE))!=NULL) {
  280.      while (fgets(was_inline, 100, deffile)!=NULL) {
  281.          specinfo = NULL ;
  282.          fontname = NULL ;
  283.          p = was_inline ;
  284.          while (*p && *p <= ' ')
  285.             p++ ;
  286.          if (*p) fontname = p ;
  287.          while (*p > ' ')
  288.             p++ ;
  289.          if (*p)
  290.             *p++ = 0 ;
  291.          while (*p && *p <= ' ')
  292.             p++ ;
  293.          if (*p != '"' && *p) {
  294.             while (*p > ' ')
  295.                p++ ;
  296.             if (*p)
  297.                *p++ = 0 ;
  298.             while (*p && *p <= ' ')
  299.                p++ ;
  300.          }
  301.          if (*p == '"') {
  302.             p++ ;
  303.             specinfo = p ;
  304.             while (*p && *p != '"')
  305.                p++ ;
  306.             *p = 0 ;
  307.          }
  308.          add_entry(newstring(fontname), newstring(specinfo)) ;
  309.        }
  310.        (void)fclose(deffile) ;
  311.    }
  312.    checkenv() ;
  313. }
  314. /*
  315.  *   Get environment variables! These override entries in ./config.h.
  316.  */
  317. checkenv() {
  318.    char *p, *getenv() ;
  319.  
  320.    if (p=getenv("TEXFONTS"))
  321.       tfmpath = newstring(p) ;
  322.    if (p=getenv("TEXPKS"))
  323.       pkpath = newstring(p) ;
  324.    if (p=getenv("TEXINPUTS"))
  325.       figpath = newstring(p) ;
  326. }
  327. @
  328.  
  329.  
  330. 1.2
  331. log
  332. @Added reasonable handling of -Pprinter option and of $PRINTER
  333. environment variable.
  334. @
  335. text
  336. @d183 3
  337. a185 2
  338.         strncpy(buf, p, dollar-p);
  339.         strcat(buf, printer ? printer : "lpr");
  340. @
  341.  
  342.  
  343. 1.1
  344. log
  345. @Initial revision
  346. @
  347. text
  348. @d150 3
  349. a152 1
  350. getdefaults() {
  351. d158 3
  352. a160 6
  353.    if (printer == NULL)
  354.       strcpy(PSname, CONFIGFILE) ;
  355.    else {
  356.       strcpy(PSname, "config.") ;
  357.       strcat(PSname, printer) ;
  358.    }
  359. d179 11
  360. a189 1
  361.          oname = newstring(p) ;
  362. @
  363.